<?php

ini_set('display_errors', 1);
error_reporting(-1);
ini_set('memory_limit', '1024M');
require_once '/data/wwwroot/g_vendor/autoload.php';

// a % b == a & ( b - 1 ) b为2的n次方，位运算性能要比直接取模高

if (!isset($argv[1]) || !isset($argv[2])) {
    exitEcho('params error!', 1);
}

$modCount = $argv[1] ?? 0;  //取模的数量
if (!$modCount || $modCount % 2 != 0) {
    exitEcho('param1 error!', 2);
}

$modValue = $argv[2] ?? 0;  //取模后的结果
if (!($modValue >= 0 && $modValue < $modCount)) {
    exitEcho('param2 error!', 3);
}

//检查活动有效期
if (time() >= strtotime(\Biz\service\springHomeDecActivity\RemindService::ACTIVITY_TIME_END)) {
    exitEcho("spring home dec activity end!", 4);
}

$ret = \Biz\service\springHomeDecActivity\RemindService::newLotteryRemind($modCount, $modValue);

exitEcho($ret);

function exitEcho($msg, $code = 0)
{
    echo sprintf("msg:%s\r\n", $msg);
    exit($code);
}